namespace Silverlight.EntityFramework
{
    public abstract class EntityValidationValue<EntityType, ValueType> : IEntityValue<EntityType, ValueType>
            where EntityType : Entity<EntityType>
    {
        private string _name;
        private ValueType _value;
        private EntityType _owner;

        public EntityValidationValue(string name, EntityType owner)
        {
            _name = name;
            _owner = owner;
        }

        public string Name { get { return _name; } }

        public ValueType Value 
        {
            get
            {
                return _value;
            }
            set 
            {
                if (Validate(value))
                {
                    _value = value;
                }
            }
        }

        public abstract bool Validate(ValueType value);

        public EntityType Entity
        {
            get
            {
                return _owner;
            }
        }
    }
}
